-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Pacay, Ariel>
-- Create date: <25/09/2011>
-- Description:	<El Select del insert es un query Dinamico de Unions>
-- =============================================
CREATE PROCEDURE [GOOGLECODERS].UsuarioRolesIns
	@QueryUnions varchar(2000) = ''
AS
BEGIN
	DECLARE @TableAux TABLE ( 
	IdUser INT NOT NULL, 
	IdRol INT NOT NULL)
	IF(@QueryUnions <> '')
	BEGIN
		INSERT INTO @TableAux (IdUser, IdRol) 
		EXEC(@QueryUnions)
		/*
		* SELECT Id, NewRol[i]
		* UNION
		* SELECT Id, NewRol[i]
		* UNION
		* SELECT Id, NewRol[i]
		*/

		INSERT INTO [GOOGLECODERS].[Usuario_x_Rol]
		SELECT IdUser, IdRol FROM @TableAux
	END
END
GO
